/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cabarrus.xltosql.util;

import java.awt.Frame;
import javax.swing.JFileChooser;

/**
 *
 * @author moscac
 */
public class FileUtility {

    public static String chooseDirectory(Frame parent, String directory, String title) {
        
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(new java.io.File(directory));
        fileChooser.setSelectedFile(new java.io.File(directory));
        fileChooser.setDialogTitle(title);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        // disable the "All files" option.
        fileChooser.setAcceptAllFileFilterUsed(false);
        if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
            return fileChooser.getSelectedFile().getAbsolutePath();
        }
        return "";
    }
    
    public static String chooseFile(Frame parent, String directory, String title) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(new java.io.File(directory));
        fileChooser.setSelectedFile(new java.io.File(directory));
        fileChooser.setDialogTitle(title);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        // disable the "All files" option.
        fileChooser.setAcceptAllFileFilterUsed(false);
        if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
            return fileChooser.getSelectedFile().getAbsolutePath();
        }
        return ""; 
    }
    
}
